package com.ruoyi.report.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.report.mapper.CommunityPolicyMapper;
import com.ruoyi.report.domain.CommunityPolicy;
import com.ruoyi.report.service.ICommunityPolicyService;

import static com.ruoyi.common.utils.DateUtils.YYYY_MM_DD_HH_MM_SS;
import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;
import static com.ruoyi.common.utils.SecurityUtils.getUsername;

/**
 * 建议信息Service业务层处理
 *
 * @author mac
 * @date 2023-02-11
 */
@Service
public class CommunityPolicyServiceImpl implements ICommunityPolicyService {
    @Autowired
    private CommunityPolicyMapper communityPolicyMapper;

    /**
     * 查询建议信息
     *
     * @param id 建议信息主键
     * @return 建议信息
     */
    @Override
    public CommunityPolicy selectCommunityPolicyById(Long id) {
        return communityPolicyMapper.selectCommunityPolicyById(id);
    }

    /**
     * 查询建议信息列表
     *
     * @param communityPolicy 建议信息
     * @return 建议信息
     */
    @Override
    public List<CommunityPolicy> selectCommunityPolicyList(CommunityPolicy communityPolicy) {
        for (SysRole role : getLoginUser().getUser().getRoles()) {
            if (role.getRoleId() == 2) {
                communityPolicy.setUsername(getUsername());
                return communityPolicyMapper.selectCommunityPolicyList(communityPolicy);
            }
        }
        return communityPolicyMapper.selectCommunityPolicyList(communityPolicy);
    }

    /**
     * 新增建议信息
     *
     * @param communityPolicy 建议信息
     * @return 结果
     */
    @Override
    public int insertCommunityPolicy(CommunityPolicy communityPolicy) {
        communityPolicy.setReleaseTime(DateUtils.dateTimeNow(YYYY_MM_DD_HH_MM_SS));
        return communityPolicyMapper.insertCommunityPolicy(communityPolicy);
    }

    /**
     * 修改建议信息
     *
     * @param communityPolicy 建议信息
     * @return 结果
     */
    @Override
    public int updateCommunityPolicy(CommunityPolicy communityPolicy) {
        return communityPolicyMapper.updateCommunityPolicy(communityPolicy);
    }

    /**
     * 批量删除建议信息
     *
     * @param ids 需要删除的建议信息主键
     * @return 结果
     */
    @Override
    public int deleteCommunityPolicyByIds(Long[] ids) {
        return communityPolicyMapper.deleteCommunityPolicyByIds(ids);
    }

    /**
     * 删除建议信息信息
     *
     * @param id 建议信息主键
     * @return 结果
     */
    @Override
    public int deleteCommunityPolicyById(Long id) {
        return communityPolicyMapper.deleteCommunityPolicyById(id);
    }
}
